package com.janko.springbootbase.designmode.proxyDynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author nyk
 * @Date 2021/6/9 14:45
 * @Version 1.0
 * @Desc
 */
public class JdkProxyWangPo implements InvocationHandler {
    KindWomen kindWomen;

    public  KindWomen getInstance(KindWomen kindWomen){
        this.kindWomen = kindWomen;
        Class<?> clazz = kindWomen.getClass();
        return (KindWomen) Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object result = method.invoke(this.kindWomen, args);
        after();
        return result;
    }

    private void after() {
        System.out.println("代理类王婆自己偷偷收了一些man的小费。");
    }
    private void before() {
        System.out.println("代理类王婆事儿后又收了潘氏的一些封口费");
    }

}
